<?php
class MainController extends AppController {
    public $layout = 'main';

    function beforeFilter() {
        parent::beforeFilter(); 
        session_start();
    }
    function index(){
		$params = $this->request->data;
    	if($this->request->is('post')){
    		$auth = $params['auth'];
    		if($_SESSION['code']==$auth){
    			echo "1";
    		}else{
    			echo "2";
    		}
    		exit();
    	}  
    }

    function mobile(){
    	$params = $this->request->data;
    	if($this->request->is('post')){
    		//短信接口地址
			$target = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
			//用户名
			$api_account = 'cf_yunyao91';
			//密码
			$api_password = 'yy0391';
			//获取手机号
			$mobile = $params['mobile'];
			//生成的随机数
			$mobile_code = Bhu::randomm(4,1);
			//短信内容
			$post_data = "account=".$api_account."&password=".$api_password."&mobile=".$mobile."&content=".rawurlencode("您的验证码是：".$mobile_code."。请不要把验证码泄露给其他人。");
			$gets =  Bhu::xml_to_array(Bhu::Post($post_data, $target));
			if($gets['SubmitResult']['code']==2){
				$_SESSION['mobile'] = $mobile;
				$_SESSION['mobile_code'] = $mobile_code;
			}
			$data=$gets;
			$_SESSION['code']=$mobile_code;
			echo json_encode($data);
			exit();
    	}  
    }
}